package com.example.smartagrisys.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.smartagrisys.entity.Inventory;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 通用库存Mapper接口
 */
@Mapper
public interface InventoryMapper extends BaseMapper<Inventory> {
    
    /**
     * 获取农户的某类型库存
     */
    @Select("SELECT * FROM inventory WHERE farmer_id = #{farmerId} AND type = #{type} AND deleted = 0")
    List<Inventory> getInventoryByType(@Param("farmerId") Long farmerId, @Param("type") String type);
    
    /**
     * 获取农户的低于预警阈值的库存
     */
    @Select("SELECT * FROM inventory WHERE farmer_id = #{farmerId} AND quantity <= alert_threshold AND deleted = 0")
    List<Inventory> getLowInventory(@Param("farmerId") Long farmerId);
} 